@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
    <style>
        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }
        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
    </style>
@endsection
@section('content')
    <link href="/lib/ueditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="/lib/ueditor/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/ueditor/umeditor.min.js"></script>
    <script type="text/javascript" src="/lib/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script src="/js/upload.js" type="text/javascript"></script>
    <script src="/js/mobileBUGFix.mini.js" type="text/javascript"></script>
    <link href="/css/ueditor.css" type="text/css" rel="stylesheet">
    <div class="content">
        <div class="header">
            <ul class="breadcrumb">
                <li><a href="/wechat/list">课程素材管理</a> </li>
                <li class="active">添加素材</li>
            </ul>
        </div>
        <div class="main-content">
            <ul class="nav nav-tabs nav-tabs-course">
                <li role="presentation" class="course_add active"><a href="javascript:void(0);">素材添加</a></li>
               <!--  <li role="presentation" class="course_hour_add"><a href="javascript:void(0);">课时添加</a></li> -->
            </ul>
            <form class="form-horizontal" id="courseFormInfo" action="/wechat/insert" method="post">
                {{csrf_field()}}
                <div class="course_class row">
                    <div class="col-md-10">
                            <br>
                            <div class="tab-content">
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-3 control-label">课程名称</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="inputEmail3" name="name" placeholder="课程名称" value="{{$item->title}}">
                                    </div>
                                </div>
                                
                                <!-- <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">是否付费</label>
                                    <div class="col-sm-9">
                                        <select class="form-control courseType" name="payFree">
                                            <option value="0">免费</option>
                                            <option value="1">付费</option>
                                        </select>
                                    </div>
                                </div> -->
                                
                                <!-- <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">作者</label>
                                    <div class="col-sm-9">
                                        <button type="button" class="btn btn-primary btn-lg" data-page="1" onclick="selectAuthor(this);">选择</button>&nbsp;&nbsp;<span style="color:blue;" id="userName"></span>
                                        <input type="hidden" class="form-control" value="" id="inputPassword3" name="author">
                                    </div>
                                </div> -->
                               
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">课程配图</label>
                                    <div class="col-sm-9">
                                        <a href="javascript:;" class="file">上传封面图()
                                            <input type="file" class="upload_img cover" name="activity_url" placeholder="封面图">
                                        </a>
                                        @if($about)
                                        <img src="{{env('WEB_URL')}}{{$about->activity_url}}" id="cover_img" style="max-height:240px;">
                                        <input type="hidden" class="cover_img" name="activity_url" value="{{$about->activity_url}}" />
                                        @else
                                        <img src="" id="cover_img" style="max-height:240px;">
                                        <input type="hidden" class="cover_img" name="activity_url" />
                                        @endif
                                        <span id="error_img_size" style="color:red;"></span>
                                    </div>
                                </div>
                                
                                 <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">课程活动配图</label>
                                    <div class="col-sm-9">
                                        <a href="javascript:;" class="file">上传封面图
                                            <input type="file" class="upload_img explain" name="activity_two_url" placeholder="封面图">
                                        </a>
                                        @if($about)
                                        <img src="{{env('WEB_URL')}}{{$about->activity_two_url}}" id="explain_img" style="max-height:240px;">
                                        <input type="hidden" class="explain_img" name="activity_two_url" value="{{$about->activity_two_url}}" />
                                        @else
                                        <img src="" id="explain_img" style="max-height:240px;">
                                        <input type="hidden" class="explain_img" name="activity_two_url" />
                                        @endif
                                        <span id="error_img_size" style="color:red;"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">微信回复关键字</label>
                                    <div class="col-sm-9">
                                        @if($about)
                                        <input type="text" class="form-control" id="inputPassword3" name="wx_keyword" placeholder="请填写课程名称关键字例如：完美腹肌" value="{{$about->wx_keyword}}" />
                                        @else
                                         <input type="text" class="form-control" id="inputPassword3" name="wx_keyword" placeholder="请填写课程名称关键字例如：完美腹肌" />
                                        @endif
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputPassword3" class="col-sm-3 control-label">添加备注</label>
                                    <div class="col-sm-9">
                                        <textarea type="text/plain" name="remark" id="myEditor" style="width:700px;height:240px;"></textarea>
                                    </div>
                                </div>

                                <div class="row">
                                    <p>
                                        @if($about)
                                        <input type="hidden" name="id" value="{{$about->id}}" />
                                        @else
                                        <input type="hidden" name="id" value="" />
                                        @endif
                                        <input type="hidden" name="course_class_id" value="{{$item->id}}" />
                                        <button type="submit" class="btn btn-primary btn-lg col-md-offset-5" style="width:120px;background:#286090;color:#fff;">提交</button>
                                    </p>
                                </div>
                            </div>
                    </div>
                </div>
            </div>
            </form>
        </div>
    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">选择作者</h4>
                </div>
                <div class="modal-body"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
    <script src="/js/ueditor.js"></script>
    <script src="/js/course.js"></script>
    <script src="/lib/jquery.validate.js" type="text/javascript"></script>
    <script>

        var imgUrl = '{{env('WEB_URL')}}';
        $(".upload_img").UploadImg({
            url : '/course/fileUploadauto',
            // width : '320',
            //height : '200',
            quality : '0.8', //压缩率，默认值为0.8
            // 如果quality是1 宽和高都未设定 则上传原图
            mixsize : '400000',
            //type : 'image/png,image/jpg,image/jpeg,image/pjpeg,image/gif,image/bmp,image/x-png',
            before : function(blob,className){
//                var className = '#'+className;
//                $(className).attr('src',blob);
            },
            error : function(res){
                $('#img').attr('src','');
                $('#error_img_size').html(res+"~亲~不能超过400kb");
            },
            success : function(url,className){
                console.log(className);
                $('#error_img_size').html("");
                var idName = '#'+className;
                var className = '.'+className;
                $(idName).attr('src',imgUrl+url);
                $(className).val(url);
            }
        });
        $("#courseFormInfo").validate({
            onsubmit: true,// 是否在提交是验证
            submitHandler: function (form) {
                var activity_url = $(".cover_img").val();
                if(activity_url == ''){
                    swal("未上传素材图片");
                    return false;
                }
                form.submit();
            }
        });
    </script>
    <style type="text/css">
        .col-sm-2{
            width:60px;
        }
        .course_content{
            margin-right: -30px;
            margin-left: -30px;
            margin-top:5px;
        }
        .btn-success{
            background-image:none!important;
        }
    </style>
@endsection